﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Windy
{
    public partial class TileSelectionForm : Form
    {
        public TileSelectionForm()
        {
            InitializeComponent();

            //System.Drawing.Bitmap Img = new System.Drawing.Bitmap("bitmap.bmp");
            ////The color at Pixel(10,10) is rendered as transparent for the complete background. 
            //Img.MakeTransparent(Img.GetPixel(10, 10));
            //this.BackgroundImage = Img;
            //this.TransparencyKey = Img.GetPixel(10, 10);
        }

        private void TileSelectionForm_Load(object sender, EventArgs e)
        {
            var panel = new Panel();
            panel.AutoSize = true;
            panel.BackColor = Color.Blue;

            int scale = 5;
            foreach (var screen in Screen.AllScreens)
            {
                Debug.WriteLine(screen.Bounds);
                var pnl = new Panel();
                pnl.BackColor = Color.WhiteSmoke;

                pnl.Location = new Point(screen.Bounds.X / scale, screen.Bounds.Y / scale);
                pnl.Size = new Size(screen.Bounds.Width / scale, screen.Bounds.Height / scale);

                panel.Controls.Add(pnl);
            }

            foreach (var btn in panel.Controls)
            {
                var b = btn as Panel;
                if (b.Location.X < 0)
                {
                    var x = b.Location.X;
                    foreach (var b2 in panel.Controls)
                    {
                        var b22 = b2 as Panel;
                        b22.Location = new Point(b22.Location.X + (x * -1));
                    }
                }
            }

            this.Controls.Add(panel);
            panel.Location = new Point(this.Width / 2 - panel.Width / 2, this.Height / 2 - panel.Height / 2);

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        //private const int WM_NCHITTEST = 0x84;
        //private const int HTTRANSPARENT = -1;

        // Code for allowing clicking through of the form
        protected override void WndProc(ref Message m)
        {
            const uint WM_NCHITTEST = 0x84;

            const int HTTRANSPARENT = -1;
            const int HTCLIENT = 1;
            const int HTCAPTION = 2;
            // ... or define an enum with all the values
            bool penMode = true;

            if (m.Msg == WM_NCHITTEST)
            {
                // If it's the message we want, handle it.
                if (penMode)
                {
                    // If we're drawing, we want to see mouse events like normal.
                    m.Result = new IntPtr(HTCLIENT);
                }
                else
                {
                    // Otherwise, we want to pass mouse events on to the desktop,
                    // as if we were not even here.
                    m.Result = new IntPtr(HTTRANSPARENT);
                }
                return;  // bail out because we've handled the message
            }

            // Otherwise, call the base class implementation for default processing.
            base.WndProc(ref m);
        }
    }
}
